#coding:utf-8
import time
from spider.BaiduNewsSpider import BaiduNewsSpider
from spider.BiyingNewsSpider import BiyingNewsSpider
from spider.BaiduSiteSpider import BaiduSiteSpider
from spider.BiyingSiteSpider import BiyingSiteSpider
from analysis.dbItems import dbXinwen,dbSiteXinwen
from run.run import run

class runXinwen(run):
    def run(self):
        baidu = BaiduNewsSpider(self.bloom,self.name)
        biying = BiyingNewsSpider(self.bloom,self.name)
        d = dbXinwen()
        rows = d.getKeywords()
        for row in rows:
            print(row[0])
            baidu.start(row[0].encode("utf8"),self.page)
            biying.start(row[0].encode("utf8"),self.page)
            d.updateKeyword(row[0])
        self.bloom.saveData()
        d.makeResult()
        self.run2()
    def run2(self):
        baidu = BaiduSiteSpider(self.bloom,self.name)
        biying = BiyingSiteSpider(self.bloom,self.name)
        d = dbSiteXinwen()
        rows = d.getSiteKeywords()
        for row in rows:
            print(row[1])
            baidu.start(row[0].encode("utf8"),row[1].encode("utf8"),self.page)
            biying.start(row[0].encode("utf8"),row[1].encode("utf8"),self.page)
            d.updateKeyword(row[1])
        self.bloom.saveData()
        d.makeResult()
if __name__=="__main__":
    a = runXinwen("news")
    a.start()